package com.zyk.scaffold.user.controller.tenantrole;


import com.zyk.scaffold.common.basic.BasicConstants;
import com.zyk.scaffold.core.domain.PageFilter;
import com.zyk.scaffold.core.domain.PageResult;
import com.zyk.scaffold.core.domain.Result;
import com.zyk.scaffold.user.service.TenantRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户-角色表 前端控制器
 * </p>
 *
 * @author zhouyk
 * @since 2021-12-06
 */
@Api(tags = "角色-API")
@RestController
@RequestMapping("/tenant-role")
public class TenantRoleController {
    @Autowired
    private TenantRoleService tenantRoleService;

    @ApiOperation("新增角色")
    @PostMapping("/newRole")
    public Result<Boolean> newRole(@RequestBody @Validated TenantRoleNewRequ tenantRoleNewRequ, @RequestHeader(BasicConstants.HEADER_USER_ID) Long userId, @RequestHeader(BasicConstants.HEADER_TENANT_CODE) String tenantCode) {
        Boolean aBoolean = tenantRoleService.newRole(tenantRoleNewRequ, userId, tenantCode);
        return Result.ok(aBoolean);
    }

    @ApiOperation("分页过滤角色")
    @PostMapping("/pageFilterRole")
    public Result<PageResult<TenantRoleInfosResp>> pageFilterRole(@RequestBody PageFilter<TenantRolePageFilterRequ> pageFilter, @RequestHeader(BasicConstants.HEADER_TENANT_CODE) String tenantCode) {
        PageResult<TenantRoleInfosResp> page = tenantRoleService.pageFilterRole(pageFilter, tenantCode);
        return Result.ok(page);
    }

    @ApiOperation("列表角色")
    @PostMapping("/listRole")
    public Result<List<TenantRoleInfosResp>> listRole(@RequestHeader(BasicConstants.HEADER_TENANT_CODE) String tenantCode) {
        List<TenantRoleInfosResp> list = tenantRoleService.listRoleAll(tenantCode);
        return Result.ok(list);
    }

    @ApiOperation("更新角色")
    @PostMapping("/editedRole")
    public Result<Boolean> editedRole(@RequestBody @Validated TenantRoleEditedRequ tenantRoleEditedRequ, @RequestHeader(BasicConstants.HEADER_USER_ID) Long userId, @RequestHeader(BasicConstants.HEADER_TENANT_CODE) String tenantCode) {
        Boolean aBoolean = tenantRoleService.editedRole(tenantRoleEditedRequ, userId, tenantCode);
        return Result.ok(aBoolean);
    }

    @ApiOperation("删除角色")
    @PostMapping("/deletedRole")
    public Result<Boolean> deleted(@RequestBody @Validated TenantRoleDeletedRequ tenantRoleDeletedRequ, @RequestHeader(BasicConstants.HEADER_USER_ID) Long userId, @RequestHeader(BasicConstants.HEADER_TENANT_CODE) String tenantCode) {
        Boolean aBoolean = tenantRoleService.deletedRole(tenantRoleDeletedRequ, userId, tenantCode);
        return Result.ok(aBoolean);
    }
}